From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Sat, 12 Oct 2024 18:24:36 +0000 (-0600) Subject: fix an annoying Wstringop-truncation warning. (#1348) X-Git-Tag: archive/raspbian/1.10.0+ds-2+rpi1~1^2~12^2^2~39 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=a4dec0acfbeb6d93a9a73e3673da983bfdd7511b;p=gpsbabel.git fix an annoying Wstringop-truncation warning. (#1348) * fix an annoying Wstringop-truncation warning. while the warning is fixed we can still index outside of the gps_categories array :( * solved stringop-truncation w/o format macro ... constants, rely on integer promotion. Also, guard against devices with more than 16 categories should they exist. --- diff --git a/jeeps/gpsapp.cc b/jeeps/gpsapp.cc index e810c9f3c..1584fc43a 100644 --- a/jeeps/gpsapp.cc +++ b/jeeps/gpsapp.cc @@ -88,7 +88,7 @@ static void GPS_D152_Send(UC* data, GPS_PWay way, int32_t* len); static void GPS_D154_Send(UC* data, GPS_PWay way, int32_t* len); static void GPS_D155_Send(UC* data, GPS_PWay way, int32_t* len); -static void GPS_D120_Get(int cat_num, char*s); +static void GPS_D120_Get(US cat_num, char*s); static void GPS_D200_Get(GPS_PWay* way, const UC* s); static void GPS_D201_Get(GPS_PWay* way, UC* s); @@ -1137,8 +1137,8 @@ int32_t GPS_A101_Get(const char* port) gpsdevh* fd; GPS_Packet tra; GPS_Packet rec; - int32_t n; - int32_t i; + US n; + US i; if (!GPS_Device_On(port,&fd)) { @@ -2021,7 +2021,7 @@ char gps_categories[16][17]; * Read descriptor s into category number N; */ static -void GPS_D120_Get(int cat_num, char* s) +void GPS_D120_Get(US cat_num, char* s) { /* we're guaranteed to have no more than 16 chars plus a * null terminator. @@ -2030,11 +2030,15 @@ void GPS_D120_Get(int cat_num, char* s) * so mimic the behaviour of the 276/296. */ - if (*s) { - strncpy(gps_categories[cat_num], s, sizeof(gps_categories[0])); + if (cat_num < 16) { + if (*s) { + strncpy(gps_categories[cat_num], s, sizeof(gps_categories[0])); + } else { + snprintf(gps_categories[cat_num], sizeof(gps_categories[0]), + "Category %d", cat_num+1); + } } else { - snprintf(gps_categories[cat_num], sizeof(gps_categories[0]), - "Category %d", cat_num+1); + GPS_Warning("GPS_D120_Get: assumption (1 <= category number <= 16) violated"); } }